/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mastercard.assets.web.struts.actions;

import com.mastercard.assets.jpa.TblGanador;
import com.mastercard.assets.web.util.to.UserLogin;
import java.io.File;
import java.io.IOException;

import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author rod
 */
public class LoginGanador
    extends
            Action
{
    public ActionForward execute(
							ActionMapping mapping , 
							ActionForm form ,
							HttpServletRequest request , 
							HttpServletResponse response )
		throws 
			IOException , 
			ServletException
    {
        HttpSession session = request.getSession( ) ;
        // en caos de null
	if( session == null )
            return mapping.findForward( "noLogin" ) ;
		
	// toma el userLogin
	UserLogin user = ( UserLogin ) session.getAttribute( "UserLogin" ) ;
		
	// en caso de null
	if( user == null )
            return mapping.findForward( "noLogin" ) ;
        
        System.out.println(":::::   Login Correcto  :::::");
        
        URL str = getServlet().getServletContext().getResource( "/fotos/" ) ; //getRequestURL().substring( 0 , 33 ) ;
        File xy = new File( str + "" ) ;
        System.out.println( xy.getAbsolutePath( ) ) ;
         
            TblGanador winner = user.getTblGanador() ;
            request.setAttribute( "Nombre", winner.getGNombre( ) ) ;
            request.setAttribute( "Apellidos", winner.getGApellido( ) ) ;
            request.setAttribute( "cve", winner.getCveGanador( ) ) ;
            
            request.setAttribute( "agenda", winner.getArchivoAgenda( ) );
            request.setAttribute( "boleto", winner.getArchivoBoleto( ) );
            request.setAttribute( "Ganador", winner ) ;
        
        
        return mapping.findForward( "success" ) ;
    }
}
